package com.zoweunion.mechanic.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.zoweunion.mechanic.dao.FacilitatorPersonnelRelationDao;
import com.zoweunion.mechanic.entity.CarPersonEntity;
import com.zoweunion.mechanic.entity.CarTemplateBean;
import com.zoweunion.mechanic.entity.FacilitatorPersonnelRelationEntity;
import com.zoweunion.mechanic.model.ResponseBean;
import com.zoweunion.mechanic.service.FacilitatorPersonnelRelationService;
import com.zoweunion.mechanic.util.ExcelUtils;
import com.zoweunion.mechanic.util.MyException;
import com.zoweunion.mechanic.util.Orgin;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.task.CarDataAbnormalTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author xp
 * @email 17688825585@163.com
 * @date 2020-07-22 16:18:41
 */
@RestController
@RequestMapping("/facilitatorRelation")
public class FacilitatorPersonnelRelationController extends BaseController {
    @Autowired
    private FacilitatorPersonnelRelationService facilitatorPersonnelRelationService;

    @Autowired
    private FacilitatorPersonnelRelationDao facilitatorPersonnelRelationDao;

    @Autowired
    private CarDataAbnormalTask carDataAbnormalTask;

    /**
     * 列表
     */
    @GetMapping("/facilitatorRelationList")
    public ResponseBean facilitatorPersonnelRelationList(@RequestParam Map<String, Object> params, HttpServletRequest request)  throws MyException{
        params.put("s_id", getCurrentUser(request).getS_id());
        params.put("user_id", getCurrentUser(request).getId());
        PageInfo info = facilitatorPersonnelRelationService.queryPage(params);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", info);
    }

    /**
     * 新增
     */
    @PostMapping("/facilitatorRelationInsertUpdate")
    public ResponseBean facilitatorPersonnelRelationInsertUpdate(@RequestBody FacilitatorPersonnelRelationEntity params,
                                             HttpServletRequest request) {
        if (params.getId()!=null){
                facilitatorPersonnelRelationService.updateById(params);
        }else {
                facilitatorPersonnelRelationService.save(params);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }


    /**
     * 添加服务商
     *
     * @param request
     * @return
     * @throws MyException
     */
    @PostMapping("/facilitatorInsert")
    public ResponseBean facilitatorInsert(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        logBefore(logger, "添加服务商");
        List<Map<String, Object>> mobilePhone = facilitatorPersonnelRelationService.getServerPhone(reqMap.get("mobile_phone").toString());
        if(mobilePhone.size()>0) {
            return new ResponseBean(Constants.CODE_HANDEL_FAILED, "服务商手机已存在", null);
        }
        List<Map<String, Object>> serverAccountList = facilitatorPersonnelRelationService.getServerAccountInfo(reqMap.get("server_account").toString());
        if (serverAccountList.size() > 0) {
            return new ResponseBean(Constants.CODE_HANDEL_FAILED, "存在多个账号,不能注册", null);
        }
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("create_user", currentUserId);
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        int result = facilitatorPersonnelRelationService.addFacilitatorUser(reqMap);

        if (result != 1) {
            return new ResponseBean(Constants.CODE_HANDEL_FAILED, "操作失败", null);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

    /**
     * 更新服务商
     *
     * @param request
     * @return
     * @throws MyException
     */
    @PostMapping("/facilitatorUpdate")
    public ResponseBean facilitatorUpdate(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        logBefore(logger, "修改服务商");
        //根据id获取服务商
        Map<String, Object> serverMap = facilitatorPersonnelRelationService.getServerById(reqMap.get("id").toString());

        List<Map<String, Object>> mobilePhone = facilitatorPersonnelRelationService.getServerPhone(reqMap.get("mobile_phone").toString());
        if(mobilePhone.size()>0) {
            if (!reqMap.get("mobile_phone").toString().equals(serverMap.get("mobile_phone").toString())) {
                return new ResponseBean(Constants.CODE_HANDEL_FAILED, "服务商手机已存在", null);
            }
        }
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        int result = facilitatorPersonnelRelationService.edit(reqMap);
        if (result != 1) {
            return new ResponseBean(Constants.CODE_HANDEL_FAILED, "操作失败", null);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

    /**
     * 删除服务商
     *
     * @param request
     * @return
     * @throws MyException
     */
    @PostMapping("/facilitatorDelete")
    public ResponseBean delete(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        int result = facilitatorPersonnelRelationService.delete(reqMap);
        if (result == 0) {
            return new ResponseBean(Constants.CODE_HANDEL_FAILED, "操作失败", null);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

    /**
     * 服务商列表
     *
     * @param request
     * @return
     * @throws MyException
     */
    @GetMapping("/facilitatorList")
    public ResponseBean facilitatorList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("current_user_id", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        reqMap.put("current_r_id", getCurrentUser(request).getR_id());
        PageInfo pageInfo = facilitatorPersonnelRelationService.facilitatorList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 金融平台-政策管理
     * 设置服务商/主机厂/子服务商的账期锁车政策
     */
    @Deprecated//转到OPS平台实现
    @PostMapping("/setFacilitatorCarLockPolicy")
    public ResponseBean setFacilitatorCarLockPolicy(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException{
        if(reqMap.get("policy_id") == null || reqMap.get("policy_id").toString() == ""){
            String create_user = getCurrentUser(request).getId();
            reqMap.put("create_user",create_user);
        }
        String update_user = getCurrentUser(request).getId();
        reqMap.put("update_user",update_user);
        int result = 0;
        if(reqMap.get("policy_id") == null || reqMap.get("policy_id").toString() == "") {
            result = facilitatorPersonnelRelationService.setFacilitatorCarLockPolicy(reqMap);
        }else{
            result = facilitatorPersonnelRelationService.updateFacilitatorCarLockPolicy(reqMap);
        }
        if(result > 0){
            return new  ResponseBean(Constants.CODE_SUCCESS,"设置成功！",null);
        }else {
            return new  ResponseBean(Constants.CODE_ERROR,"设置失败！",null);
        }

    }

    /**
     * 新增车主人员
     *
     * @param request
     * @return
     * @throws MyException
     */
    @PostMapping("/carPersonInsert")
    public ResponseBean carPersonInsert(@RequestBody CarPersonEntity carPersonEntity, HttpServletRequest request) throws MyException {
        carPersonEntity.setSid(getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.carPersonInsert(carPersonEntity);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

    /**
     * 更新人员信息
     *
     * @param request
     * @return
     * @throws MyException
     */
    @PostMapping("/carPersonUpdate")
    public ResponseBean carPersonUpdate(@RequestBody CarPersonEntity carPersonEntity, HttpServletRequest request) throws MyException {
        carPersonEntity.setSid(getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.carPersonUpdate(carPersonEntity);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

    /**
     * 车辆列表
     */
    @GetMapping("/carList")
    public ResponseBean carList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        if (!reqMap.containsKey("server_sid")){
            reqMap.put("server_sid", getCurrentUser(request).getS_id());
        }
        PageInfo pageInfo = facilitatorPersonnelRelationService.carList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 车辆列表加报警
     */
    @GetMapping("/carListCountAlarm")
    public ResponseBean carListCountAlarm(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        if (!reqMap.containsKey("server_sid")){
            reqMap.put("server_sid", getCurrentUser(request).getS_id());
        }
        PageInfo pageInfo = facilitatorPersonnelRelationService.carListCountAlarm(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 报警列表
     */
    @GetMapping("/alarmList")
    public ResponseBean alarmList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        PageInfo pageInfo = facilitatorPersonnelRelationService.alarmList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 车辆详情
     */
    @GetMapping("/carInfo")
    public ResponseBean carInfo(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        List<Map<String, Object>> list = facilitatorPersonnelRelationService.carInfo(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", list);
    }

    /**
     * 删除车辆人员绑定
     */
    @PostMapping("/carDelete")
    public ResponseBean carDelete(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.carDelete(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 车辆删除
     */
    @PostMapping("/carListDelete")
    public ResponseBean carListDelete(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.carListDelete(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }


    /**
     * 车辆列表
     *
     * @param request
     * @return
     * @throws MyException
     */
    @GetMapping("/facilitatorCarList")
    public ResponseBean facilitatorCarList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        PageInfo pageInfo = facilitatorPersonnelRelationService.facilitatorCarList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }


    /**
     * 查询政府下服务商列表
     *
     * @param request
     * @return
     * @throws MyException
     */
    @GetMapping("/facilitatorByList")
    public ResponseBean facilitatorByList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        reqMap.put("server_sid", getCurrentUser(request).getS_id());
        List<Map<String, Object>> maps = facilitatorPersonnelRelationService.facilitatorByList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", maps);
    }

    /**
     * 操作证列表
     */
    @GetMapping("/certificateList")
    public ResponseBean certificateList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        PageInfo pageInfo = facilitatorPersonnelRelationService.certificateList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 操作证总数
     */
    @GetMapping("/certificateCount")
    public ResponseBean certificateCount(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String currentUserId = getCurrentUser(request).getId();
        reqMap.put("update_user", currentUserId);
        int certificateCount = facilitatorPersonnelRelationService.certificateCount(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", certificateCount);
    }

    /**
     * 添加设备进行绑定
     */
    @GetMapping("/equipmentList")
    public ResponseBean equipmentList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        if (!reqMap.containsKey("sid")) {
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        PageInfo pageInfo = facilitatorPersonnelRelationService.equipmentList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 批量添加物联网卡进行绑定
     */
    @PostMapping("/insertEquipmentList")
    public ResponseBean insertEquipmentList(@RequestBody CarPersonEntity reqMap, HttpServletRequest request) throws MyException {
        facilitatorPersonnelRelationService.insertEquipmentList(reqMap.getThingsIds(),
                reqMap.getSid(),getCurrentUser(request).getS_id());
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 金融平台：批量添加物联网卡进行绑定
     */
    @PostMapping("/insertEquipmentListOfFinancial")
    public ResponseBean insertEquipmentListOfFinancial(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String financial_id = getCurrentUser(request).getS_id();
        String update_user =  getCurrentUser(request).getId();
        reqMap.put("financial_id",financial_id);
        reqMap.put("update_user",update_user);
        int result = facilitatorPersonnelRelationService.insertEquipmentListOfFinancial(reqMap);
        if (result == 2) {
            return new ResponseBean(Constants.CODE_HANDEL_FAILED, "不能添加已存在的物联网卡", null);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

    /**
     * 设备列表
     */
    @GetMapping("/equipmentListAll")
    public ResponseBean equipmentListAll(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        if (!reqMap.containsKey("sid")) {
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        PageInfo pageInfo = facilitatorPersonnelRelationService.equipmentListAll(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 批量解除绑定
     */
    @PostMapping("/deleteEquipmentBatch")
    public ResponseBean deleteEquipmentBatch(@RequestBody CarPersonEntity reqMap, HttpServletRequest request) throws MyException {
        facilitatorPersonnelRelationService.deleteEquipmentBatch(reqMap.getThingsIds()
                , reqMap.getSid(), getCurrentUser(request).getS_id());
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 金融平台下主机厂、服务商批量解除绑定(退回操作)
     */
    @PostMapping("/deleteEquipmentBatchOfFinancial")
    public ResponseBean deleteEquipmentBatchOfFinancial(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String update_user = getCurrentUser(request).getId();
        String financial_id = getCurrentUser(request).getS_id();
        reqMap.put("financial_id",financial_id);
        reqMap.put("update_user", update_user);
        facilitatorPersonnelRelationService.deleteEquipmentBatchOfFinancial(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 设备列表(解绑)
     */
    @GetMapping("/equipmentListRemove")
    public ResponseBean equipmentListRemove(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        if (!reqMap.containsKey("sid")){
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        List<String> equipmentList =
                facilitatorPersonnelRelationService.equipmentListRemove(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", equipmentList);
    }

    /**
     * 车辆下拉列表临时新
     */
    @GetMapping("/selectCarListCon")
    public ResponseBean selectCarListCon(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        reqMap.put("sid", getCurrentUser(request).getS_id());
        List<Map<String, Object>> selectCarListCon =
                facilitatorPersonnelRelationService.selectCarListCon(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", selectCarListCon);
    }

    /**
     * 人脸车辆新增临时新
     */
    @PostMapping("/insertHuman")
    public ResponseBean insertHuman(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        reqMap.put("sid", getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.insertHuman(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 更新faceId
     */
    @PostMapping("/updateHuman")
    public ResponseBean updateHuman(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        reqMap.put("sid", getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.updateHuman(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 识别身份证照片
     */
    @PostMapping("/uploadCarId")
    public ResponseBean uploadCarId(@RequestParam("file") MultipartFile file, HttpServletResponse response)  throws MyException {
        Object carId = facilitatorPersonnelRelationService.uploadCarId(file);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", carId);
    }

    /**
     * 获取编辑服务商
     *
     * @param str
     * @param request
     * @return
     * @throws MyException
     */
    @PostMapping("/getFacilitatorInfo")
    public ResponseBean getFacilitatorInfo(@RequestBody String str, HttpServletRequest request) throws MyException {
        Map<String, Object> reqMap = JSONObject.parseObject(str, Map.class);
        Map<String, Object> resultMap = facilitatorPersonnelRelationService.getFacilitatorInfo(reqMap.get("id").toString());
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", resultMap);
    }

    /**
     * 制造商列表
     */
    @GetMapping("/manuList")
    public ResponseBean manuList(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        if (!reqMap.containsKey("sid")){
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        PageInfo equipmentList =
                facilitatorPersonnelRelationService.manuList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", equipmentList);
    }

    /**
     * 批量添加绑定
     */
    @PostMapping("/insertManu")
    public ResponseBean insertManu(@RequestBody CarPersonEntity reqMap, HttpServletRequest request) throws MyException {
        facilitatorPersonnelRelationService.insertManu(reqMap.getThingsIds(),
                reqMap.getSid());
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 制造商列表
     */
    @GetMapping("/manuListBySid")
    public ResponseBean manuListBySid(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        if (!reqMap.containsKey("sid")) {
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        PageInfo equipmentList =
                facilitatorPersonnelRelationService.manuListBySid(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", equipmentList);
    }

    /**
     * 批量解除绑定
     */
    @PostMapping("/removeManu")
    public ResponseBean removeManu(@RequestBody CarPersonEntity reqMap, HttpServletRequest request) throws MyException {
        reqMap.setSid(getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.removeManu(reqMap.getThingsIds(),
                reqMap.getSid());
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 批量添加生产商设备
     */
    @PostMapping("/insertManuBySid")
    public ResponseBean insertManuBySid(@RequestBody CarPersonEntity userEntity, HttpServletRequest request) throws MyException {
        userEntity.setSid(getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.insertManuBySid(userEntity);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 删除制造编号
     */
    @PostMapping("/deleteManuByFac")
    public ResponseBean deleteManuByFac(@RequestBody CarPersonEntity userEntity, HttpServletRequest request) throws MyException {
        userEntity.setSid(getCurrentUser(request).getS_id());
        facilitatorPersonnelRelationService.deleteManuByFac(userEntity);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     *  车辆列表
     */
    @GetMapping("/carBySid")
    public ResponseBean carBySid(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        if (!reqMap.containsKey("sid")){
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        PageInfo equipmentList =
                facilitatorPersonnelRelationService.carBySid(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", equipmentList);
    }

    /**
     *  车辆列表
     */
    @GetMapping("/carForSid")
    public ResponseBean carForSid(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        // facilitatorPersonnelRelationService.pushDay();
        if (!reqMap.containsKey("sid")){
            reqMap.put("sid", getCurrentUser(request).getS_id());
        }
        PageInfo equipmentList =
                facilitatorPersonnelRelationService.carForSid(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", equipmentList);
    }

    /**
     * 下载模板
     */
    @GetMapping("/downTemplate")
    public void downTemplate( HttpServletResponse response) throws Exception {
        ExcelUtils.exportExcelToTarget(response, "车辆导出模板", new ArrayList<>(),
                CarTemplateBean.class);
    }

    /**
     * 导入
     * @param multipartFile
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    public ResponseBean upload(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request) throws Exception {
        ImportParams params = new ImportParams();
        List<CarTemplateBean> result = ExcelImportUtil.importExcel(multipartFile.getInputStream(),
                CarTemplateBean.class, params);
        facilitatorPersonnelRelationService.importCarList(result, getCurrentUser(request).getS_id());
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     *  车辆列表
     */
    @GetMapping("/ktbltest")
    public ResponseBean ktbltest(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {

        //facilitatorPersonnelRelationService.pushDay(Orgin.getIntValue(reqMap,"day"));

        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    @GetMapping("/ktbltestmoni")
    public ResponseBean ktbltestmoni(@RequestParam Map<String, Object> reqMap, HttpServletRequest request) throws MyException {

        facilitatorPersonnelRelationService.pushMoNiDay(Orgin.getIntValue(reqMap,"day"));
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 服务商锁车权限变更（主机厂变更子服务商）
     * @body reqMap
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadLockLimit")
    public ResponseBean uploadLockLimit(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws Exception {
        facilitatorPersonnelRelationService.uploadLockLimit(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", "");
    }

    /**
     * 金融平台获取车主申请记录
     * @body reqMap
     * @return
     * @throws Exception
     */
    @PostMapping("/getCarOwnerApplyUnlockList")
    public ResponseBean getCarOwnerApplyUnlockList(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String sId = getCurrentUser(request).getS_id();
        reqMap.put("s_id", sId);
        PageInfo<Map<String, Object>> pageInfo = facilitatorPersonnelRelationService.getCarOwnerApplyUnlockList(reqMap);
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", pageInfo);
    }

    /**
     * 金融平台更新车主申请记录(通过、拒绝)
     * @body reqMap
     * @return
     * @throws Exception
     */
    @PostMapping("/updateOwnerApplyUnlockById")
    public ResponseBean updateOwnerApplyUnlockById(@RequestBody Map<String, Object> reqMap, HttpServletRequest request) throws MyException {
        String userId = getCurrentUser(request).getId();
        String userName = getCurrentUser(request).getUser_name();
        String sId = getCurrentUser(request).getS_id();
        reqMap.put("user_id", userId);
        reqMap.put("userName", userName);
        reqMap.put("s_id", sId);
        int result = facilitatorPersonnelRelationService.updateOwnerApplyUnlockById(reqMap);
        if(result > 0) {
            if(reqMap.get("apply_status").toString().equals("1")) {
                Map<String, Object> carMap = facilitatorPersonnelRelationDao.getCarInfoWithOwnerInfo(Orgin.getString(reqMap, "c_id"));
                carDataAbnormalTask.jPushApplicationPassed(carMap);
            }
            if(reqMap.get("apply_status").toString().equals("3")) {
                Map<String, Object> carMap = facilitatorPersonnelRelationDao.getCarInfoWithOwnerInfo(Orgin.getString(reqMap, "c_id"));
                carDataAbnormalTask.jPushApplicationReject(carMap);
            }

            return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
        }
        return new ResponseBean(Constants.CODE_SUCCESS, "操作成功", null);
    }

}
